<?php
include_once('../init.php');
include("../i.php");

/*登录后执行函数*/
function login() {
	$action = trim(_g('action'));
	switch($action) {
	case moduleTree:
		moduleTree();
		break;
	default:
		showModule();
	}
}

/*默认执行方法*/
function showIndex() {
	$url = '../';
	$time = 2;
	$msg = '请登录后在进入';
	redirect($url,$time,$msg);
}

function moduleTree() {
	global $config,$userInfo;
	$Role = new Role();
	$data = $Role->roleTreeSort();
	foreach ($data as $key=>$value){
		//if($value['display'] == 'block') {
			$dataShow[] = $value;
		//}
	}
	$avail['id'] = '-1';
	$avail['text'] = '无选择项';
	$avail['iconCls'] = 'icon-cancel';
	$dataShow[] = $avail;
	$dataShow = getTree($dataShow,$userInfo['roleid'],1);
	exit(json_encode($dataShow));
}

function showModule() {
	global $userInfo;
	$Role = new Role();
	$data = $Role->roleTreeSort();
	foreach ($data as $key=>$value){
		if($value['display'] == 'block') {
			$dataShow[] = $value;
		}
	}
	$dataShow = getTree($dataShow,$userInfo['roleid']);
	exit(json_encode($dataShow));
}







//print_r($tree);























































































//把所有的先看成都有子分类
function dataChildren($dataArray) {
	foreach ($dataArray as $key=>$value){
		$data[$value['id']]['text'] = $value['text'];
		$data[$value['id']]['state'] = 'open';
		$data[$value['id']]['id'] = $value['id'];
		$data[$value['id']]['pid'] = $value['pid'];
		$data[$value['id']]['children'] = array();
		$data[$value['id']]['attributes']['file'] = '';
		$data[$value['id']]['attributes']['action'] = '';
	}
	return $data;
}



//把节点归类
function classChildren($dataArray) {
	foreach ($dataArray as $key=>&$value){
		$data = $dataArray[$value['pid']];
		if(!empty($data)) {
			unset($value['']);
			$dataArray[$value['pid']]['children'][] = $value;
			unset($dataArray[$value['id']]);
		}
	}
	return $dataArray;
}
//array_push();


//	array(
//		"text"=>"用户管理",
//		"state"=>"open",
//		"children"=>array(
//			array("text"=>"用户列表","attributes"=>array("file"=>"user","action"=>"list")),
//		)
//	),





//// 获得最在深度
//$depth = 0;
//foreach ($rs AS $k => $v) {
//    if ($v['depth'] > $depth){
//        $depth = $v['depth'];
//	}
//}
//print_r($tree);
//// 组合
//function getChildren($array, $depth, $id = 0) {
//    foreach ($array AS $k => $v) {
//        if ($v['pid'] == $id) {
//            $arr[] = $v;
//            if ($v['depth'] < $depth) {
//                $c = getChildren($array, $depth, $v['id']);
//                if ($c)
//                    $v['children'] = $c;
//            }
//        }
//    }
//    return $arr;
//}

//print_r($tree);
//print_r($menu);
//$menu = array(
//	array(
//		"text"=>"系统配置",
//		"state"=>"open",
//		"children"=>array(
//			array("text"=>"应用配置","attributes"=>array("file"=>"system","action"=>"list")),
//			array(
//			"text"=>"用户管理",
//			"state"=>"open",
//			"children"=>array(
//				array("text"=>"用户列表","attributes"=>array("file"=>"user","action"=>"list")),
//			)
//		 ),
//		)
//	),
//	array(
//		"text"=>"用户管理",
//		"state"=>"open",
//		"children"=>array(
//			array("text"=>"用户列表","attributes"=>array("file"=>"user","action"=>"list")),
//		)
//	),
//);
//exit(json_encode($menu));

?>
